home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWResour / FWLbInit.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.9 KB  |  142 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLbInit.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWCFMRES_H
  13. #include "FWCFMRes.h"
  14. #endif
  15.  
  16. #ifndef _ODMEMORY_
  17. #include <ODMemory.h>
  18. #endif
  19.  
  20. #if defined(SYMANTEC_CPLUS) && defined(FW_BUILD_MAC)
  21.     #define ODFCFMINIT PartCFMInit
  22. #endif
  23.  
  24. //========================================================================================
  25. // Prototypes
  26. //========================================================================================
  27.  
  28. #ifdef FW_BUILD_MAC
  29. extern "C" pascal OSErr ODFCFMINIT (CFragInitBlockPtr initBlkPtr);
  30. extern "C" pascal void  ODFCFMTERM (void);
  31.  
  32. #ifdef __MWERKS__
  33. #    if __MWERKS__ < 0x0800
  34. extern "C" void __sinit();
  35. extern "C" void    __destroy_global_chain(void);
  36. #    else
  37. extern "C" short __initialize();
  38. extern "C" void    __terminate(void);
  39. #    endif
  40. #elif defined __MRC__
  41. extern "C" __init_lib(CFragInitBlockPtr initBlkPtr);
  42. #endif
  43.  
  44. #endif // FW_BUILD_MAC
  45.  
  46. //========================================================================================
  47. //    Global Variable
  48. //========================================================================================
  49. //    FW_gInstance is initialized in DLLMain for Windows
  50. //    FW_gInstance is defined in FWCFMRes.cpp for the Mac
  51. #ifdef FW_BUILD_WIN
  52. FW_Instance FW_gInstance = NULL;
  53. #endif
  54.  
  55. //========================================================================================
  56. // Initialization methods
  57. //========================================================================================
  58.  
  59. #ifdef FW_BUILD_WIN32
  60. //----------------------------------------------------------------------------------------
  61. // DllMain
  62. //----------------------------------------------------------------------------------------
  63. extern "C" BOOL WINAPI DllMain(HINSTANCE    hDLL,
  64.                     DWORD        dwReason,
  65.                     LPVOID        /* lpReserved */)
  66. {
  67.     if(dwReason == DLL_PROCESS_ATTACH)
  68.     {
  69.         // Save instance handle for future use
  70.         FW_gInstance = hDLL;
  71.     }
  72.  
  73.     return TRUE;
  74. }
  75. #endif
  76.  
  77. #ifdef FW_BUILD_MAC
  78. //----------------------------------------------------------------------------------------
  79. // ODFCFMINIT (Has to be upper case because of the 68K Linker)
  80. //----------------------------------------------------------------------------------------
  81.  
  82. extern "C" pascal OSErr ODFCFMINIT(CFragInitBlockPtr initBlkPtr)
  83. {
  84. #ifdef FW_DEBUG
  85.     #define FW_COMMAND 0x37
  86.     
  87.     KeyMap theKeyMap;
  88.     ::GetKeys(theKeyMap);
  89.     const unsigned char *theKeys = (const unsigned char *) theKeyMap;
  90.     if ((theKeys[FW_COMMAND >> 3] >> (FW_COMMAND & 7)) & 1)
  91.         ::DebugStr("\pODFCFMInit");
  92. #endif
  93.  
  94.     // Shared libraries don't get there static objects initialized correctly without
  95.     // calling __initialize or __CPlusInit for MetroWerks or MrC respectively.
  96. #ifdef __MWERKS__
  97.     #if __MWERKS__ < 0x0800
  98.         __sinit();
  99.     #else
  100.         __initialize();
  101.     #endif
  102. #elif defined __MRC__
  103.     __init_lib(initBlkPtr);
  104. #endif
  105.     
  106. #ifndef FW_NATIVE_EXCEPTIONS
  107.     // FW_gInStaticInit is initialized to a special magic number before static initialization (at linktime)
  108.     // within SLExcept.cpp.  Here we clear it to zero.  This allows FWExcLib to
  109.     // understand when static objects are being constructed.
  110.     extern long FW_gInStaticInit;
  111.     FW_gInStaticInit = 0L;
  112. #endif
  113.     
  114.     OSErr err1  = ::InitODMemory();
  115.  
  116.     OSErr err2 = FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(initBlkPtr);
  117.  
  118.     return (OSErr)(err1 != noErr) ? err1 : err2;
  119. }
  120. #endif
  121.  
  122. #ifdef FW_BUILD_MAC
  123. //----------------------------------------------------------------------------------------
  124. // ODFCFMTERM
  125. //----------------------------------------------------------------------------------------
  126.  
  127. extern "C" pascal void ODFCFMTERM(void)
  128. {
  129.     FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources();
  130.     
  131. #ifdef __MWERKS__
  132. #        if __MWERKS__ < 0x0800
  133.     __destroy_global_chain();
  134. #        else
  135.     __terminate();
  136. #        endif
  137. #endif
  138.     
  139. }
  140. #endif
  141.  
  142.